//
//  ViewControllerForUser.m
//  ProjectA
//
//  Created by dllo on 16/3/2.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "ViewControllerForUser.h"
#import "CellForUser.h"

@interface ViewControllerForUser ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation ViewControllerForUser
- (void)dealloc {
    
    [_tableView release];
    [super dealloc];
}

- (void)setNightDayModel {
    [super setNightDayModel];
    
    self.barBackgroundView.backgroundColor = RGBA(52, 52, 52, 52);
    self.navigationItem.rightBarButtonItem.tintColor = L_COLOR_WHITE;
}
- (void)setLightDayModel {
    [super setLightDayModel];
   
    self.barBackgroundView.backgroundColor = RGBA(44, 211, 209, 1);
    self.navigationItem.rightBarButtonItem.tintColor = L_COLOR_WHITE;

}
- (void)viewWillAppear:(BOOL)animated {
    
    if (ISNIGHT) {
        [self setNightDayModel];
    } else {
        [self setLightDayModel];
    }
}
- (void)viewWillDisappear:(BOOL)animated {
    self.barBackgroundView.backgroundColor = L_COLOR_CLEAR;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self settingsNavigationController];
    
    [self createTableView];
    
}
- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.backgroundColor = [UIColor clearColor];
    
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];
    
    [self.tableView registerClass:[CellForUser class] forCellReuseIdentifier:@"pool"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool1"];
    [self.tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"poolForHeader"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (0 == section) return 2;
    if (1 == section) return 2;
                      return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 15;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (0 == indexPath.section && 0 == indexPath.row) return 80;
    
                                                      return 50;
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"poolForHeader"];
    if (ISNIGHT) {
        view.contentView.backgroundColor = L_COLOR_GRAY;
    } else {
        view.contentView.backgroundColor = RGBA(255, 251, 222, 1);
    }
    return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"pool1"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (ISNIGHT) {
        cell.backgroundColor = RGBA(52, 52, 52, 1);
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.detailTextLabel.textColor = [UIColor whiteColor];
    } else {
        cell.backgroundColor = [UIColor whiteColor];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.detailTextLabel.textColor = [UIColor blackColor];
    }
    if (0 == indexPath.section) {
        if (0 == indexPath.row) {
            CellForUser *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (ISNIGHT) {
                cell.backgroundColor = RGBA(52, 52, 52, 1);
                cell.labelForIcon.textColor = [UIColor whiteColor];
                cell.detailTextLabel.textColor = [UIColor whiteColor];
            } else {
                cell.backgroundColor = [UIColor whiteColor];
                cell.labelForIcon.textColor = [UIColor blackColor];
                cell.detailTextLabel.textColor = [UIColor blackColor];
            }
            cell.labelForIcon.text = @"头像";
            NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"登录"];
            [cell.imageViewForIcon sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"iconURL"]]];
            return cell;
        }
        if (1 == indexPath.row) {
            cell.textLabel.text = @"用户名";
            NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"登录"];
            cell.detailTextLabel.text = [dic objectForKey:@"name"];
            return cell;
        }
    }
    if (1 == indexPath.section) {
        if (0 == indexPath.row) {
            cell.textLabel.text = @"手机号码";
            cell.detailTextLabel.text = @"未设置";
            return cell;
        }
        if (1 == indexPath.row) {
            
            cell.textLabel.text = @"邮箱";
            cell.detailTextLabel.text = @"未设置";
            return cell;
        }
    }
    if (2 == indexPath.section) {
        if (0 == indexPath.row) {

            cell.textLabel.text = @"地区";
            cell.detailTextLabel.text = @"请选择";
            return cell;
        }
        if (1 == indexPath.row) {

            cell.textLabel.text = @"性别";
            cell.detailTextLabel.text = @"请选择";
            return cell;
        }
        if (2 == indexPath.row) {

            cell.textLabel.text = @"生日";
            cell.detailTextLabel.text = @"请选择";
            return cell;
        }
    }
    cell.textLabel.text = @"个性签名";
    cell.detailTextLabel.text = @"未设置";
    return cell;
    
}
- (void)settingsNavigationController {
    
    self.navigationItem.title = @"个人信息";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui(heise)"] style:UIBarButtonItemStylePlain target:self action:@selector(houtuiAction:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"退出" style:UIBarButtonItemStylePlain target:self action:@selector(tuichuAction:)];
    
    
  
}
- (void)tuichuAction:(UIBarButtonItem *) button {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定要推出当前账户吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"登录"];
        [self.navigationController popViewControllerAnimated:YES];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action2];
    [alert addAction:action1];
    [self presentViewController:alert animated:YES completion:nil];
    
}
- (void)houtuiAction:(UIBarButtonItem *) item {
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
